package edu.bw.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class ServiceAdvice {

    public void before(JoinPoint joinPoint){
        System.out.println("before"+"  "+ Arrays.toString(joinPoint.getArgs())+"  "+joinPoint.getSignature());
    }
    public void after(){
        System.out.println("after");
    }
    public void afterReturning(Object o){
        System.out.println("afterReturning"+"方法返回值"+o);
    }
    public void afterThrowing(Throwable e){
        System.out.println("afterThrowing"+"异常"+e);
    }

    public void around(ProceedingJoinPoint joinPoint){
        System.out.println("around before");
        try {
            joinPoint.proceed();//相当于执行方法，返回值就是方法的返回值
        } catch (Throwable e) {
            System.out.println("around afterThrowing");
            throw new RuntimeException(e);
        }finally {
            System.out.println("around after");
        }
    }
}
